<template>
	<view class="uni-container">
		<!-- <uni-nav-bar dark :fixed="true" shadow background-color="#007AFF" status-bar left-icon="left" left-text="返回"
			title="公租房" @clickLeft="back" /> -->
			<cu-custom bgColor="bg-gradual-blue" :isBack="true">
				<block slot="backText">返回</block>
				<block slot="content">公租房</block>
			</cu-custom>
		<view class="scorll-style">
			<view v-for="(item,index) in tableData" :key="index" class="c-list" >
				<uni-card :title="item.title" mode="title" :is-shadow="true" :extra="item.project_dictText" note="Tips">
					<view>
						当前进度：
						<uni-tag :text="item.isStopApply ===0?'正在报名':'停止报名'"
							:type="item.isStopApply ===0?'success':'error'" :inverted="true"></uni-tag>
						<uni-tag :text="item.isStopCheck ===0?'正在核查':'停止核查'"
							:type="item.isStopCheck ===0?'success':'error'" :inverted="true"></uni-tag>
						<uni-tag :text="item.isFinish ===0?'进行中':'已结束'" :type="item.isFinish ===0?'success':'error'"
							:inverted="true"></uni-tag>
					</view>
					<view>
						当前阶段：{{item.currentStatus_dictText}}
					</view>
					<view slot="actions" class="card-actions">
						<!-- <button size="mini" class="btn1" @click="getscore(item.id)">计分</button> -->
						<button size="mini" class="btn2" @click="signUp(item.id)">报名</button>
					</view>
				</uni-card>
			</view>
		</view>
		<view>
			<!-- 提示窗示例 -->
			<uni-popup ref="alertDialog" type="dialog">
				<uni-popup-dialog type="info" cancelText="取消" confirmText="前往报名" title="通知" :content="messageText"
					@confirm="applyOnclick(msgType)" @close="dialogClose"></uni-popup-dialog>
			</uni-popup>
		</view>
	</view>
</template>

<script>
	export default {
		name: 'publicRentalHousing',
		data() {
			return {
				flag: 0,
				tableData: [{
					title: 'xx项目公租房报名',
					project_dictText: '',
					isStopApply_dictText: '',
					isStopCheck_dictText: '',
					isFinish_dictText: '',
					currentStatus_dictText: '',
				}],
				pageSize: 10,
				// 当前页
				pageCurrent: 1,
				// 数据总量
				total: 0,
				person: [0, 1, 2, 3],
				msgType: 'success',
				messageText: '这是一条成功提示',
				
				userApplyReminderModel: {
				  canApply: false,
				  applyidx: '',
				},
			}
		},
		mounted() {
			this.$http.get('/applyinfo/znzfApply/list').then(res => {
				console.log(1, res.data.result.records)
				this.tableData = res.data.result.records
			})
		},
		methods: {
			employeeApplyCheckInfo(e){
				this.userApplyReminderModel = {
				  canApply: false,
				  applyidx: e,
				};
				this.$http.get(`/applyinfo/znzfApply/checkapplyinfo/${e}`).then((res) => {
					res = res.data;
				  if (res.success) {
					if(res.result.canApply){
						this.dialogToggle('success', res.result.message.replace(/&/g, "\n"))
					}
					else{
						this.dialogToggle('warn', res.result.message.replace(/&/g, "\n"))
					}
					this.userApplyReminderModel.canApply = res.result.canApply;
				  }
				  else{
					uni.showToast({
						title: res.message,
						icon: 'error',
						duration: 2000
					});
				  }
				})
			},
			signUp(e) {
				let project = this.tableData.filter(item => item.id == e)[0]
				// console.log(project)
				this.employeeApplyCheckInfo(e);
				
			},
			getscore(id){
				// this.$refs.message.open()
				// this.$Router.push({
				// 	name: 'signUp'
				// })
				let temp = {id:id}
				this.$Router.push({name: 'getSum',params:temp})
			},
			applyOnclick(){
				if(!this.userApplyReminderModel.canApply){
					uni.showToast({
						title: '您当前不符合报名条件！',
						icon: 'error',
						duration: 2000
					});
					return;
				}
				if(!this.userApplyReminderModel.applyidx){
					uni.showToast({
						title: '提交错误！',
						icon: 'error',
						duration: 2000
					});
					return;
				}
				let params ={id: this.userApplyReminderModel.applyidx}
				this.$http.post('/applyapartemployee/znzfApplyApartEmployee/submitapply', params).then((res) => {
				  res = res.data;
				  if (res.success) {
					uni.showToast({
						title: '报名成功',
						duration: 2000
					});
				  }
				  else{
					uni.showToast({
						title: res.message,
						icon: 'error',
						duration: 2000
					});
				  }
				})
			},
			back() {
				this.$router.go(-1)
			},
			// 分页触发
			change(e) {
				this.$refs.table.clearSelection()
				this.selectedIndexs.length = 0
				this.getData(e.current)
			},
			dialogToggle(type, text) {
				this.msgType = type
				this.messageText = text
				this.$refs.alertDialog.open()
			},
			dialogClose() {
				console.log('点击关闭')
			},
		}
	}
</script>

<style lang="scss">
	.scorll-style {
		margin-top: 20px;
		width: 100%;
		overflow-x: auto;
	}

	.caozuo {
		display: flex;
	}

	.card-actions {
		padding-bottom: 20upx;
		display: flex;

		.btn1 {
			color: #FFFFFF;
			background-color: #00aa00;
			width: 45%;
			float: left;
		}

		.btn2 {
			color: #FFFFFF;
			background-color: #007AFF;
			width: 45%;
			float: right;
		}
	}
</style>
